package com.itany.controller;

import com.github.pagehelper.PageInfo;
import com.itany.pojo.Menu;
import com.itany.pojo.Permission;
import com.itany.service.PermissionService;
import com.itany.vo.ActionResult;
import com.itany.vo.PermissionVo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.awt.*;
import java.util.*;
import java.util.List;

import static java.awt.SystemColor.menu;

@RestController
@RequestMapping("/permission")
public class PermissionController {

    @Resource
    private PermissionService permissionService;

    @RequestMapping("/findParents")
    public List<Permission> findParents(){
        List<Permission> all = permissionService.findParents();
        return all;
    }

    @RequestMapping("/findMenu")
    public ActionResult findMenu(){
        ActionResult ar = new ActionResult();
        TreeSet<Menu> menu = permissionService.findMenu(0);
        ar.setData(menu);
        return ar;
    }

    @RequestMapping("/findByFuzzy")
    public Map<String,Object> findByFuzzy(Permission permission, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "5") Integer rows){
        Map<String,Object> map = new HashMap<>();
        PageInfo<Permission> permissionPageInfo = permissionService.findByFuzzy(permission, page, rows);
        map.put("total",permissionPageInfo.getTotal());
        map.put("rows",permissionPageInfo.getList());
        return map;
    }

    @RequestMapping("/modifyById")
    public ActionResult modifyById(Permission permission){
        ActionResult ar = new ActionResult();
        permissionService.modifyById(permission);
        ar.setStatus(true);
        return ar;
    }
}
